package com.zuoye.Serviecs;

import com.zuoye.entity.Account;
import com.zuoye.inter.IRepay;

import java.util.Scanner;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/15  19:48
 * @Copyright
 */
public class CreitAccount extends Account implements IRepay {
    //信用卡
    private double ceiling;
    public Scanner scanner = new Scanner(System.in);

    public CreitAccount() {

    }

    public double getCeiling() {
        return ceiling;
    }

    public double setCeiling(double ceiling) {
        this.ceiling = ceiling;
        return ceiling;
    }

    public CreitAccount(String cardNo, String password, double balance) {
        super(cardNo, password, balance);
    }

    @Override
    public double deposit(double money, String number, String password) {
        return 0;
    }


    public CreitAccount(String cardNo, String password, double balance, double ceiling) {
        super(cardNo, password, balance);
        this.ceiling = ceiling;

    }


    @Override
    public void loan(double money, String number, String password) {
        double ceil01 = this.setCeiling(15000);
        double ceil02 = this.setCeiling(20000);
        double ceil03 = this.setCeiling(25000);

        System.out.println("----------------------------------------------------");
        System.out.println("存款在1万~3万之间的，额度为：" + ceil01 + "元");
        System.out.println("存款在3万~8万之间的，额度为：" + ceil02 + "元");
        System.out.println("存款在8万~15万之间的，额度为：" + ceil03 + "元");
        System.out.println("-----------------------------------------------------");


        for (int i = 0; i < Back.accounts.length; i++) {
            if (Back.accounts[i].cardNo.equals(number) && Back.accounts[i].password.equals(password)) {
                do {
                    if (10000 < Back.accounts[i].balance && Back.accounts[i].balance <= 30000) {
                        System.out.println("您的额度为：" + ceil01 + "元");
                        do {

                            System.out.println("请输入要取出的金额：");
                            money = scanner.nextDouble();
                            if (money > ceil01) {
                                System.out.println("对不起，您的额度不足，请重新输入");

                            } else {
                                System.out.println("已取出金额：" + money);
                                System.out.println("剩余金额为：" + (ceil01 - money));
                                ceil01 = ceil01 - money;
                                System.out.println("是否继续取：");
                                String s1 = scanner.next();
                                if (s1.equals("是")) {
                                    continue;
                                } else {
                                    break;
                                }

                            }
                            break;
                        } while (true);
                        break;
                    } else if (30000 < Back.accounts[i].balance && Back.accounts[i].balance <= 80000) {
                        System.out.println("您的额度为：" + ceil02 + "元");
                        do {

                            System.out.println("请输入要取出的金额：");
                            money = scanner.nextDouble();
                            if (money > ceil02) {
                                System.out.println("对不起，您的额度不足，请重新输入");

                            } else {
                                System.out.println("已取出金额：" + money);
                                System.out.println("剩余金额为：" + (ceil02 - money));
                                ceil02 = ceil02 - money;
                                System.out.println("是否继续取：");
                                String s1 = scanner.next();
                                if (s1.equals("是")) {
                                    continue;
                                } else {
                                    break;
                                }
                            }
                            break;
                        } while (true);
                    } else if (80000 < Back.accounts[i].balance && Back.accounts[i].balance <= 150000) {
                        System.out.println("您的额度为：" + ceil03 + "元");
                        do {

                            System.out.println("请输入要取出的金额：");
                            money = scanner.nextDouble();
                            if (money > ceil03) {
                                System.out.println("对不起，您的额度不足，请重新输入");

                            } else {
                                System.out.println("已取出金额：" + money);
                                System.out.println("剩余金额为：" + (ceil03 - money));
                                ceil03 = ceil03 - money;
                                System.out.println("是否继续取：");
                                String s1 = scanner.next();
                                if (s1.equals("是")) {
                                    continue;
                                } else {
                                    break;
                                }

                            }
                        } while (true);
                    } else if (Back.accounts[i].balance > 150000) {
                        double ceil04 = this.setCeiling(100000);
                        System.out.println("您太有钱了!为你您Vip额度");
                        System.out.println("您的额度为：" + ceil04 + "元");
                        do {

                            System.out.println("请输入要取出的金额：");
                            money = scanner.nextDouble();
                            if (money > ceil04) {
                                System.out.println("对不起，您的额度不足，请重新输入");

                            } else {
                                System.out.println("已取出金额：" + money);
                                System.out.println("剩余金额为：" + (ceil04 - money));
                                ceil04 = ceil04 - money;
                                System.out.println("是否继续取：");
                                String s1 = scanner.next();
                                if (s1.equals("是")) {
                                    continue;
                                } else {
                                    break;
                                }
                            }

                        } while (true);
                    }


                } while (true);
            }

        }
    }
}